/**
 *	@define:hjc -> core -> 基础游戏对象
 */

namespace hjc {

	export abstract class GameObject extends egret.DisplayObject {

		protected $center: egret.Point;//几何中心点
		protected $radius: number;//逻辑半径
		protected static className;//对象池名称

		//设置逻辑半径
		protected ui(radius: number = null): void {
			ui.resetAnchorCenter(this);
			this.$radius = radius ? radius : Math.avg(this.width, this.height);
		}

		//设置几何中心
		public set center(center: egret.Point) {
			this.$center = center;
			this.x = center.x;
			this.y = center.y;
		}

		//获得几何中心
		public get center(): egret.Point {
			if (!this.$center) this.$center = new egret.Point();
			this.$center.x = this.x;
			this.$center.y = this.y;
			return this.$center;
		}

		//获得逻辑半径
		public get radius(): number { return this.$radius; };

		//获得与指定点的距离
		public getDisFrom(target: GameObject, considerRadius: boolean = true): number {
			if (!considerRadius) return utils.disOfPoints(this.center, target.center);
			let dis = utils.disOfPoints(this.center, target.center) - this.$radius - target.$radius;
			return dis < 0 ? 0 : dis;
		}

		public abstract setAs(like: any): void;
		public onCreate(): void { };
		public onUpdate(): void { };
		public onDestroy(): void { };
	}

}